﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Nancy;
using Nancy.Security;
using Nancy.Authentication.Forms;

namespace Nancy.Demos.Login.Models
{
    [Serializable]
    public class UserInfo
    {
        public string UserName { get; set; }
        public string Password { get; set; }
    }


    public class UserIdentity : IUserIdentity
    {
        public UserIdentity(string userName) :
            this(userName, new List<string>())
        {
        }
        public UserIdentity(string userName, IEnumerable<string> claims)
        {
            this.UserName = userName;
            this.Claims = claims;
        }

        public IEnumerable<string> Claims
        {
            get;
            private set;
        }

        public string UserName
        {
            get;
            private set;
        }
    }
    public class UserMapper : IUserMapper
    {
        public IUserIdentity GetUserFromIdentifier(Guid identifier, NancyContext context)
        {
            UserInfo userRecord = context.Request.Session[identifier.ToString()] as UserInfo;

            return userRecord == null ? null
               : new UserIdentity(userRecord.UserName);
        }
    }



}